package com.cheejee.goodscenter.module.response;

import java.io.Serializable;
import java.time.LocalDateTime;

import com.cheejee.goodscenter.util.ResponseCode;

import lombok.Data;

/**
 * 基本响应实体类
 * 
 * @author CARRY
 * @Date 2020年10月22日下午5:45:15
 */
@Data
public class BaseReponse implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1699887612225622290L;

	/**
	 * 响应码
	 */
	protected int code;

	/**
	 * 提示信息
	 */
	protected String message;

	/**
	 * 时间
	 */
	protected LocalDateTime time;

	protected Object data;

	public BaseReponse(ResponseCode code, String message) {
		this(code, message, null);
	}

	public BaseReponse(ResponseCode code, String message, Object data) {
		this.time = LocalDateTime.now();
		this.code = code.getCode();
		this.message = message;
		this.data = data;
	}

	public static BaseReponse ok(String message) {
		return new BaseReponse(ResponseCode.OK, message);
	}

	public static BaseReponse ok(String message, Object data) {
		return new BaseReponse(ResponseCode.OK, message, data);
	}
	
	/**
	 * code:2000
	 * message:查询完成
	 *
	 * @param data
	 * @return
	 */
	public static BaseReponse queryOk(Object data) {
		return new BaseReponse(ResponseCode.OK, "查询完成", data);
	}
	
	/**
	 * code:2000
	 * message:新增完成
	 *
	 * @param data
	 * @return
	 */
	public static BaseReponse addOk(Object data) {
		return new BaseReponse(ResponseCode.OK, "新增完成", data);
	}
	
	/**
	 * code:2000
	 * message:修改完成
	 *
	 * @param data
	 * @return
	 */
	public static BaseReponse changeOk(Object data) {
		return new BaseReponse(ResponseCode.OK, "修改完成", data);
	}
	
	/**
	 * code:2000
	 * message:删除完成
	 *
	 * @param data
	 * @return
	 */
	public static BaseReponse deleteOk() {
		return new BaseReponse(ResponseCode.OK, "删除完成", null);
	}
}
